package com.luoran.bartalks.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NumberValidationUtils {

	private static boolean isMatch(String regex, String orginal) {
		if (orginal == null || orginal.trim().equals("")) {
			return false;
		}
		Pattern pattern = Pattern.compile(regex);
		Matcher isNum = pattern.matcher(orginal);
		return isNum.matches();
	}

	/**
	 * 正整数，可以带+号，第一个数字不能为0
	 * 
	 * @param orginal
	 * @return
	 */
	public static boolean isPositiveInteger(String orginal) {
		return isMatch("^\\+{0,1}[1-9]\\d*", orginal);
	}

	/**
	 * 负整数，必须带负号，第一个数字也不能为0
	 * 
	 * @param orginal
	 * @return
	 */
	public static boolean isNegativeInteger(String orginal) {
		return isMatch("^-[1-9]\\d*", orginal);
	}

	/**
	 * 整数，由0，正整数和负整数组成的，前两个方法一起判断
	 * 
	 * @param orginal
	 * @return
	 */
	public static boolean isWholeNumber(String orginal) {
		return isMatch("[+-]{0,1}0", orginal) || isPositiveInteger(orginal) || isNegativeInteger(orginal);
	}


	/**
	 * 小数，必须带负号
	 * 
	 * @param orginal
	 * @return
	 */
	public static boolean isNegativeDecimal(String orginal) {
		return isMatch("^-[0]\\.[1-9]*|^-[1-9]\\d*\\.\\d*", orginal);
	}

	/**
	 * 小数，可以带正负号左边不为空和右边不为空
	 * 
	 * @param orginal
	 * @return
	 */
	public static boolean isDecimal(String orginal) {
		return isMatch("[-+]{0,1}\\d+\\.\\d*|[-+]{0,1}\\d*\\.\\d+", orginal);
	}
	
	/**判断是否为小数
	 * @param orginal
	 * @return
	 */
	public static boolean isNegative(String orginal) {
		
		return isMatch("^[0-9]+(.[0-9]+)?$",orginal);
	}
	

	/**
	 * 
	 * 
	 * @param orginal
	 * @return
	 */
	public static boolean isPositive(String orginal) {
		return isPositiveInteger(orginal) || (isDecimal(orginal)&&isNegative(orginal));
	}

	/**
	 * 要么是整数，要么是小数
	 * 
	 * @param orginal
	 * @return
	 */
	public static boolean isRealNumber(String orginal) {
		return isWholeNumber(orginal) || isDecimal(orginal);
	}
	
	
	

	public static void main(String[] args) {
		String orginal="10.0";
		System.out.println(isPositiveInteger(orginal));
		System.out.println(isDecimal(orginal));
		System.out.println(isNegative(orginal));
	

	}

}
